<?php
/**
 * User: hjd-yao
 * Date: 2019/5/6
 * Time: 18:39
 */

namespace App\Http\Controllers\Store;


use App\Helpers\Search;
use App\Http\Controllers\BackendController;
use App\Models\Shop\OrderModel;
use DC\UserCenter\Models\UserBaseModel;
use Illuminate\Http\Request;
use Store\Models\StoreModel;

class StoreOrderController extends BackendController
{
    /**
     * @title 商户订单
     * @param Request $request
     * @return View
     */
    public function storeOrders(Request $request)
    {
        $search = Search::make($request)->bindModel(OrderModel::with('goods'))
            ->input('order_sn','订单编号')->input('uid','会员')
            ->input('store_id','商户名称')
            ->time('created_at','下单时间')->bindSearchData()
            ->relationModel(['uid'=>function($value){
                return UserBaseModel::where('user_number',$value)->value('member_id');
            },'store_id'=>function($value){
                return StoreModel::where('store_name',$value)->value('store_id');
            }]);

        $list = $search->where()->where('store_id','>',0)->paginate($this->getPerPageNum());
        return view('backend::shop.order.list',[
            'page_title'=>'店铺订单',
            'list'=>$list,
            'search'=>$search
        ]);
    }
}